<?php
		try {
			$stomp = new Stomp('tcp://10.51.235.167:61613?jms.optimizeAcknowledge=false',"topicsender","QniZ2S9NE6qN7KqJ");
			
			$tag_id = trim($_GET["tag_id"]);
			if (!preg_match("/^\d*$/", $tag_id)) { 
				$return["code"]=15;
				$return["msg"]="tag_id只能是数字！";
			}
			$sid = trim($_GET["sid"]);
			if (!preg_match("/^\d*$/", $sid)) { 
				$return["code"]=15;
				$return["msg"]="sid只能是数字！";
			}
			$add_log_id = trim($_GET["add_log_id"]);
			if (!preg_match("/^\d*$/", $add_log_id)) { 
				$return["code"]=15;
				$return["msg"]="add_log_id只能是数字！";
			}
			$buyer_nick = htmlspecialchars(trim(urldecode($_GET["buyer_nick"])));
			if (!$buyer_nick) { 
				$return["code"]=15;
				$return["msg"]="必须有buyer_nick！";
			}
			if(isset($return)){
				throw new Exception($return["msg"]);
			}
			$countdown = (int)($_GET["countdown"]);
			$quere = trim($_GET["quere"]);
			$msgBody = array(
						"tag_id"=>$tag_id,
						"buyer_nick"=>$buyer_nick,
						"sid"=>$sid,
						"add_log_id"=>$add_log_id,
						"ts"=>time(),
						);
			$msgHeader["persistent"] = "true"; // VERY IMPORTANT : Because By default, Stomp produced messages are set to non-persistent.
			$msgHeader["transformation"] = "jms-map-json";
			$msgHeader["AMQ_SCHEDULED_DELAY"] = $countdown*60*1000;//延时
			$mapMessage = new StompFrame("SEND",$msgHeader,json_encode($msgBody));
			
			/* begin a transaction */
			$stomp->begin('jms-map-json');

			/* send a message to the queue */
			$stomp->send('/queue/'.$quere, $mapMessage, array('transaction' => 'jms-map-json'));

			/* commit */
			$stomp->commit('jms-map-json');

			unset($stomp);
			$return["code"]=200;
			$return["msg"]="成功发送消息";
			echo json_encode($return);
			
		} catch (Exception $e) {
			$return["code"]=15;
			$return["msg"]=$e->getMessage();
			echo json_encode($return);
		}

		/*
		if(msg instanceof BytesMessage){  
			BytesMessage bm = (BytesMessage) msg;  
			byte[] bys = null;  
			try {  
				bys = new byte[(int) bm.getBodyLength()];  
				bm.readBytes(bys);  
				responseXml = new String(bys);  
			} catch (Exception e) {  
				System.out.println(e.getMessage());
				e.printStackTrace();  
			}  
		}else{  
			TextMessage bm = (TextMessage) msg;  
  
			try {  
				responseXml = bm.getText();  
			} catch (Exception e) {  
				System.out.println(e.getMessage()); 
			}  
		}  
		
		org.apache.activemq.command.ActiveMQMapMessage cannot be cast to javax.jms.TextMessage
		
		*/